home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 11675 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.2 KB

  1. Path: druid.borland.com!usenet
  2. From: pete@borland.com (Pete Becker)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Beginer C please help me
  5. Date: 25 Mar 1996 19:13:23 GMT
  6. Organization: Borland International
  7. Message-ID: <4j6r8j$hfm@druid.borland.com>
  8. References: <4irjqa$jtn@winx03.informatik.uni-wuerzburg.de> <827821769.0snx@n16872.pc.jaring.my>
  9. NNTP-Posting-Host: pbecker.borland.com
  10. Mime-Version: 1.0
  11. Content-Type: Text/Plain; charset=ISO-8859-1
  12. X-Newsreader: WinVN 0.99.5
  13.  
  14. In article <827821769.0snx@n16872.pc.jaring.my>, ckyin@n16872.pc.jaring.my 
  15. says...
  16. >
  17. >
  18. >  I agree with you completely. What a complete nonsense!  
  19. >  
  20. >  In order a get correct answer, should try this:
  21. >
  22. >     n = 9.0/5  or n = 9/5.0 or  n = 9/5*1.0 
  23. >
  24. >  Remember, in C you may not get a floating point answer by division
  25. >  using integer only!
  26. >
  27. >  I hope this will help!
  28.  
  29. Unfortunately, two out of three is still bad.   n = 9/5*1.0 will assign 1.0 to 
  30. n. Multiplication and division have the same precedence, and they group from 
  31. left to right. This means that the compiler looks first at 9/5, and concludes 
  32. that this is integer arithmethic. Then it looks at *1.0, promotes the result of 
  33. the integer division to double, and performs the multiplication.
  34.     -- Pete
  35.  
  36.